#include<AT89X52.h>
unsigned char savage[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};

void key_scan()
{
int x,y;
P1=0xfe;
P2=0xf0;					   
if(P2==0xf0)
{}
else if(P2==0xe0)
{
x=3;
}
else if(P2==0xd0)
{
x=2;
}
else if(P2==0xb0)
{
x=1;
}
else if(P2==0x70)
{
x=0;
}
P2=0x0f;
if(P2==0x0f)
{}
if(P2==0x0e)
{
y=0;
}
else if(P2==0x0d)
{
y=1;
}
else if(P2==0x0b)
{
y=2;
}
else if(P2==0x07)
{
y=3;
}
P0=savage[x+4*y];
}

void function4()
{
   while(1)
  {
   key_scan();
  }
}